<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('版本列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">

            <div class="wrapper wrapper-content animated fadeInRight ibox-content">
                <form class="form-horizontal m" id="form-version-add">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">版本号：</label>
                        <div class="col-sm-8">
                            <input name="virsionNum" class="form-control" type="text">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">是否强制更新：</label>
                        <div class="col-sm-8">
                            <div class="radio-box">
                                <select name="mustUpdate">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">版本说明：</label>
                        <div class="col-sm-8">
                            <textarea name="descrip" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">安装包路径：</label>
                        <div class="col-sm-8">
                            <input id="filePath" name="filePath" class="form-control" type="file">
                            <textarea id="updateUrl" name="updateUrl" class="form-control"></textarea>
                        </div>
                    </div>
                </form>
                <div style="margin-left: 50%">
                    <a class="btn btn-success" onclick="submitHandler()" >
                        <i class="fa fa-plus"></i> 提交
                    </a>
                </div>
            </div>


            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        document.getElementById('filePath').addEventListener('change', function (event) {
            var $file = event.currentTarget;
            var formData = new FormData();
            var file = $file.files;
            formData = new FormData();
            formData.append('fileName',file[0].name);
            formData.append("file", file[0]);
            $.ajax({
                url: ctx + "system/info/publicAdd",
                type: 'POST',
                dataType: 'json',
                data: formData,
                contentType: false,
                processData: false
            })
                .done(data => {
                    console.log(data);
                    $('#updateUrl').val(data.filePath);
                })
                .fail(data => {
                    console.log(data);
                });
        });

        var prefix2 = ctx + "system/version"
        $("#form-version-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix2 + "/add", $('#form-version-add').serialize());
            }
        }

        var editFlag = [[${@permission.hasPermi('system:version:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:version:remove')}]];
        var prefix = ctx + "system/version";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "版本",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '序号',
                },
                {
                    field: 'virsionNum',
                    title: '版本号'
                },
                {
                    field: 'creator',
                    title: '上传人'
                }/*,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }*/]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>
